package com.cat.model.web.action.api;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.alonew.core.commons.util.TimeUtil;
import com.cat.model.biz.service.api.ReservationService;
import com.cat.model.common.model.common.ReservationVO;
import com.cat.model.common.model.common.UserTokenVO;
import com.cat.model.common.util.ErrorCode;
import com.cat.model.dao.mapper.UserInfoMapper;
import com.cat.model.web.action.base.BaseAction;

public class ReservationAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 604080577375901309L;
	
	private String token;
	private Long reservationId;
	private Integer page;
	private Integer size;
	
	private String modelRequirement;//模特需求
	private String workStartTime;//工作开始时间
	private String workEndTime;//工作结束时间
	private String workCityCode;//工作城市
	private String workAddress;//工作地点
	private String workType;//工作类型
	private Integer workHours;//总工作小时数
	private String serviceBrand;//服务品牌
	private String remark;//备注
	private BigDecimal totalAmount;//总金额
	private String phoneNo;//联系人电话
	private String name;//联系人姓名
	private String modelData;//模特预约信息
	
	@Autowired
	private UserInfoMapper userInfoMapper;
	
	@Autowired
	private ReservationService reservationService;
	
	/**
	 * 预约单列表
	 * */
	public void list(){
		if(StringUtils.isEmpty(token)||page==null||size==null){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		
		print(reservationService.reservationList(userToken.getUserId(),page,size));
	}
	
	/**
	 * 生成模特预约单
	 * */
	public void createModelReservation(){
		if(StringUtils.isEmpty(token)){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		
		ReservationVO reservation = new ReservationVO();
		reservation.setWorkAddress(workAddress);
		reservation.setModelRequirement(modelRequirement);
//		if(StringUtils.isNotEmpty(workStartTime)){
//			Date workStartDateTime = TimeUtil.parse("yyyy-MM-dd hh:mm:ss", workStartTime);
//			reservation.setWorkStartTime(workStartDateTime);
//		}
//		if(StringUtils.isNotEmpty(workEndTime)){
//			Date workEndDateTime = TimeUtil.parse("yyyy-MM-dd hh:mm:ss", workEndTime);
//			reservation.setWorkEndTime(workEndDateTime);
//		}
//		reservation.setWorkHours(workHours);
		reservation.setWorkCityCode(workCityCode);
		reservation.setWorkType(workType);
		reservation.setServiceBrand(serviceBrand);
		reservation.setTotalAmount(totalAmount);
		reservation.setRemark(remark);
		reservation.setPhoneNo(phoneNo);
		reservation.setName(name);
		
		print(reservationService.createModelReservation(userToken.getUserId(), reservation,modelData));
	}
	
	/**
	 * 预约单信息查询
	 * */
	public void reservationInfo(){
		if(reservationId==null){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		
		print(reservationService.reservationInfo(reservationId));
	}
	
	/**
	 * 模特预约单确认
	 * */
	public void confirmModelReservation(){
		if(StringUtils.isEmpty(token)||reservationId==null){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		
		print(reservationService.confirmModelReservation(userToken.getUserId(), reservationId));
	}

	/**
	 * 模特预约单取消
	 * */
	public void cancelModelReservation(){
		if(StringUtils.isEmpty(token)||reservationId==null){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		
		print(reservationService.cancelModelReservation(userToken.getUserId(), reservationId));
	}
	
	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getSize() {
		return size;
	}

	public void setSize(Integer size) {
		this.size = size;
	}

	public Long getReservationId() {
		return reservationId;
	}

	public void setReservationId(Long reservationId) {
		this.reservationId = reservationId;
	}

	public String getModelRequirement() {
		return modelRequirement;
	}

	public void setModelRequirement(String modelRequirement) {
		this.modelRequirement = modelRequirement;
	}

	public String getWorkStartTime() {
		return workStartTime;
	}

	public void setWorkStartTime(String workStartTime) {
		this.workStartTime = workStartTime;
	}

	public String getWorkEndTime() {
		return workEndTime;
	}

	public void setWorkEndTime(String workEndTime) {
		this.workEndTime = workEndTime;
	}

	public String getWorkCityCode() {
		return workCityCode;
	}

	public void setWorkCityCode(String workCityCode) {
		this.workCityCode = workCityCode;
	}

	public String getWorkAddress() {
		return workAddress;
	}

	public void setWorkAddress(String workAddress) {
		this.workAddress = workAddress;
	}

	public String getWorkType() {
		return workType;
	}

	public void setWorkType(String workType) {
		this.workType = workType;
	}

	public Integer getWorkHours() {
		return workHours;
	}

	public void setWorkHours(Integer workHours) {
		this.workHours = workHours;
	}

	public String getServiceBrand() {
		return serviceBrand;
	}

	public void setServiceBrand(String serviceBrand) {
		this.serviceBrand = serviceBrand;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public BigDecimal getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(BigDecimal totalAmount) {
		this.totalAmount = totalAmount;
	}

	public String getPhoneNo() {
		return phoneNo;
	}

	public void setPhoneNo(String phoneNo) {
		this.phoneNo = phoneNo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getModelData() {
		return modelData;
	}

	public void setModelData(String modelData) {
		this.modelData = modelData;
	}

}
